-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove unnecessary deserialization actions #14904
Conversation
if (_isDistributed) | ||
{ | ||
data = await _distributedCache.GetAsync(_options.CacheKey); | ||
byte[] data = await _distributedCache.GetAsync(_options.CacheKey); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use var data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the suggestion feature instead
{ | ||
return null; | ||
} | ||
return await _options.Serializer.DeserializeAsync<TDocument>(data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add an empty line after the ending }
brace
} | ||
else if (_memoryCache.TryGetValue<TDocument>(_options.CacheKey, out var cached)) | ||
{ | ||
data = await _options.Serializer.SerializeAsync(cached); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact there is a reason for doing this, this only happens if not distributed and on updating, when we want to get a mutable document for updating for which we don't want to return a shared document from the memory cache.
So serializing and deserializing is a way to clone the document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your reply. I didn't think of these, maybe we should add some notes to the text here
if (_isDistributed) | ||
{ | ||
data = await _distributedCache.GetAsync(_options.CacheKey); | ||
byte[] data = await _distributedCache.GetAsync(_options.CacheKey); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use the suggestion feature instead
if (_isDistributed) | ||
{ | ||
data = await _distributedCache.GetAsync(_options.CacheKey); | ||
byte[] data = await _distributedCache.GetAsync(_options.CacheKey); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
byte[] data = await _distributedCache.GetAsync(_options.CacheKey); | |
var data = await _distributedCache.GetAsync(_options.CacheKey); |
{ | ||
return null; | ||
} | ||
return await _options.Serializer.DeserializeAsync<TDocument>(data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return await _options.Serializer.DeserializeAsync<TDocument>(data); | |
return await _options.Serializer.DeserializeAsync<TDocument>(data); |
When distributed caching is not enabled, redundant serialization and deserialization actions are performed